package com.yotoodesign.dianba.ui;

import java.util.ArrayList;

import android.widget.Toast;

import com.baidu.mapapi.map.MKEvent;
import com.baidu.mapapi.search.MKAddrInfo;
import com.baidu.mapapi.search.MKBusLineResult;
import com.baidu.mapapi.search.MKDrivingRouteResult;
import com.baidu.mapapi.search.MKPoiInfo;
import com.baidu.mapapi.search.MKPoiResult;
import com.baidu.mapapi.search.MKSearchListener;
import com.baidu.mapapi.search.MKSuggestionResult;
import com.baidu.mapapi.search.MKTransitRouteResult;
import com.baidu.mapapi.search.MKWalkingRouteResult;
import com.yotoodesign.dianba.app.GlobalApplication;

public class MySearchListener implements MKSearchListener {

	public CallbackListener callback;
	public ArrayList<MKPoiInfo> poiResult;
	/*
	 * 返回地址信息搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetAddrResult(com.baidu.mapapi.search.MKAddrInfo, int)
	 */
	@Override
	public void onGetAddrResult(MKAddrInfo arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	/*
	 * 返回公交车详情信息搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetBusDetailResult(com.baidu.mapapi.search.MKBusLineResult, int)
	 */
	@Override
	public void onGetBusDetailResult(MKBusLineResult arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	/*
	 * 返回驾乘路线搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetDrivingRouteResult(com.baidu.mapapi.search.MKDrivingRouteResult, int)
	 */
	@Override
	public void onGetDrivingRouteResult(MKDrivingRouteResult arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	/*
	 * 返回poi详情搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetPoiDetailSearchResult(int, int)
	 */
	@Override
	public void onGetPoiDetailSearchResult(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	/*
	 * 返回poi搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetPoiResult(com.baidu.mapapi.search.MKPoiResult, int, int)
	 */
	@Override
	public void onGetPoiResult(MKPoiResult res, int type, int error) {
		// TODO Auto-generated method stub
		if (error == MKEvent.ERROR_RESULT_NOT_FOUND) {
			Toast.makeText(GlobalApplication.getMainActivity(), "抱歉，未找到结果",
					Toast.LENGTH_LONG).show();
			return;

		}
		else if (error != 0 || res == null) {

			Toast.makeText(GlobalApplication.getMainActivity(), "搜索出错啦..",
					Toast.LENGTH_LONG).show();
			return;

		}
		
		poiResult = res.getAllPoi();
		if(callback!=null){
			callback.execute(poiResult);
		}
	}

	/*
	 * 返回联想词信息搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetSuggestionResult(com.baidu.mapapi.search.MKSuggestionResult, int)
	 */
	@Override
	public void onGetSuggestionResult(MKSuggestionResult arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	/*
	 * 返回公交搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetTransitRouteResult(com.baidu.mapapi.search.MKTransitRouteResult, int)
	 */
	@Override
	public void onGetTransitRouteResult(MKTransitRouteResult arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	/*
	 * 返回步行路线搜索结果
	 * @see com.baidu.mapapi.search.MKSearchListener#onGetWalkingRouteResult(com.baidu.mapapi.search.MKWalkingRouteResult, int)
	 */
	@Override
	public void onGetWalkingRouteResult(MKWalkingRouteResult arg0, int arg1) {
		// TODO Auto-generated method stub

	}

}
